<template>
  <div>
    <!-- list -->
    <el-table
      v-loading="loading"
      :data="list"
      border
      style="width: 98%; margin: 0 auto"
    >
      <el-table-column align="center" label="评论id" width="100">
        <template slot-scope="scope">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="用户id" width="120">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="文章id" width="100">
        <template slot-scope="scope">
          {{ scope.row.image }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="父id" width="60px">
        <template slot-scope="scope">
          {{ scope.row.status }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="内容" width="350">
        <template slot-scope="scope">
          {{ scope.row.sort }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="创建时间" width="150">
        <template slot-scope="scope">
          {{ scope.row.created_at }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="是否已读" width="100px">
        <template slot-scope="scope">
          {{ scope.row.updated_at }}
        </template>
      </el-table-column>

      <el-table-column align="center" label="用户id" width="100px">
        <template slot-scope="scope">
          {{ scope.row.member.id }}
        </template>
      </el-table-column>

      <el-table-column align="center" label="用户账号" width="200px">
        <template slot-scope="scope">
          {{ scope.row.member.account }}
        </template>
      </el-table-column>

      <el-table-column align="center" label="文章id" width="100px">
        <template slot-scope="scope">
          {{ scope.row.article.id }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="文章标题" width="100px">
        <template slot-scope="scope">
          {{ scope.row.article.title }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="200px">
        <template slot-scope="scope">
          <el-popconfirm
            cancel-button-text="取消"
            confirm-button-text="确定"
            icon="el-icon-info"
            icon-color="red"
            title="这是一段内容确定删除吗？"
            @confirm="confirmDelete(scope.row.id)"
          >
            <el-button
              slot="reference"
              icon="el-icon-delete"
              size="mini"
              style="margin-left: 20px"
              type="danger"
              >删除</el-button
            >
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { c, s } from "@/api/pl";
import { Message } from "element-ui";
export default {
  name: "hezuohb",
  data() {
    return {
      list: [],
      loading: true,
      formLabelWidth: "120px",
    };
  },
  methods: {
    // 获取页面
    async fetchDate() {
      await c().then((response) => {
        if (response.code == 200) {
          this.loading = false;
          const { data } = response.data;
          this.list = data;
        }
      });
    },
    // 删除
    async deleteThis(id) {
      await s(id).then((response) => {
        this.loading = true;
        if (response.code == 200) {
          setTimeout(() => {
            this.loading = false;
            Message.info({
              message: "删除成功",
            });
          }, 1300);
          this.fetchDate();
        }
      });
    },
    confirmDelete(a) {
      this.deleteThis(a);
    },
  },
  created() {
    this.fetchDate();
  },
};
</script>

<style scoped>
</style>
